package com.app.service.impl;

import com.app.common.EducationTool;
import com.app.mapper.jiuquan.TbcConfigMapper;
import com.app.model.TbcConfigModel;
import com.app.service.TbcConfigService;
import com.app.util.StringTool;
import com.app.vo.EducationVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbcConfigServiceImpl extends ServiceImpl<TbcConfigMapper, TbcConfigModel> implements TbcConfigService {

    @Autowired
    private TbcConfigMapper tbcConfigMapper;
    //获取所有民族
    @Override
    public List<TbcConfigModel> getNationList() {
        QueryWrapper<TbcConfigModel> qw =new QueryWrapper<>();
        qw.eq("con_type",1);
        List<TbcConfigModel> tbcConfigList = tbcConfigMapper.selectList(qw);
        for (TbcConfigModel tbcConfig : tbcConfigList) {
            tbcConfig.setConType(null);
        }
        return tbcConfigList;
    }
    //获取所有学历
    @Override
    public List<EducationVo> getEducationList() {
        List<EducationVo> educationVoList = EducationTool.EDUCATION_VO_LIST;
        return educationVoList;
    }

    @Override
    public Page<TbcConfigModel> findByNewsTypePage(String comName, Integer page, Integer limit) {
        QueryWrapper<TbcConfigModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("con_type", 6);
        if (StringTool.isNotEmpty(comName)) {
            queryWrapper.like("name", comName);
        }
        Page<TbcConfigModel> pages = new Page<>();
        pages.setCurrent(page);
        pages.setSize(limit);
        Page<TbcConfigModel> configModelPage = tbcConfigMapper.selectPage(pages, queryWrapper);
        if (configModelPage == null) {
            return null;
        } else {
            for (int i = 0; i < configModelPage.getRecords().size(); i++) {
                if (configModelPage.getRecords().get(i).getFatherId() != null && configModelPage.getRecords().get(i).getFatherId() > 0) {
                    TbcConfigModel model = getModelById(configModelPage.getRecords().get(i).getFatherId());
                    configModelPage.getRecords().get(i).setFatherIdText(model.getName());
                }
            }
            return configModelPage;
        }
    }

    @Override
    public List<TbcConfigModel> getGroupListByType(Integer type, Integer fatherId) {
        QueryWrapper<TbcConfigModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("con_type", type);
        if (fatherId != null) {
            queryWrapper.eq("father_id", fatherId);
        }
        return tbcConfigMapper.selectList(queryWrapper);
    }
    @Override
    public TbcConfigModel getModelById(Integer id) {
        return tbcConfigMapper.selectById(id);
    }

}
